<template>
  <div class="subContainer">

    <div v-show="$route.meta.isShow" class="header">
      <div class="wb-header" style="position: fixed;top: 0; box-sizing: border-box; width: 100%; z-index: 1000;">
        <van-icon name="wap-home-o" @click="toHome" />
        <div class="wb_logo">
          <img src="../../assets/headerxxx.jpg" alt="">
        </div>
        <div class="icon">
          <van-icon name="search" @click="toSearch" />
          <van-icon name="shopping-cart-o" @click="toShopCart" style="margin-left: 10px; margin-right: 1px" />
        </div>
      </div>
    </div>
    <div class="cd-nav">
      <van-tabs sticky style="position: fixed; " v-model='defaultIndex' @click="getNewList">
        <van-tab :title="cateL2.name" v-for="(cateL2,index) in cateShopList.categoryL2List" :key="cateL2.id"></van-tab>

      </van-tabs>
    </div>

    <div class="bd">
      <div class="whiteBd">
        <span class="text">{{categoryTitle.frontName}}</span>
      </div>
    </div>
    <!-- 列表 -->
    <div class="shopList">
      <div class="two">
        <div class="shopItem" @click="toDetail(item.id)" v-for="(item, index) in itemList" :key="item.id">
          <div class="itemImg">
            <img class="img" :src="item.scenePicUrl" alt="">
          </div>

          <div class="itemName">
            {{item.name}}
          </div>
          <span class="textPrice">￥{{item.counterPrice}}</span>

        </div>

      </div>

    </div>

    <!-- 最底部 -->
    <div class="statusBar">
      <div class="text">更多内容, 敬请期待</div>
    </div>

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'SubCateList',
  data() {
    return {
      defaultIndex: 0,
      // subId: 0,
      // cateId: 0,
      itemId: ''
    }
  },

  mounted() {

    this.getNewList()

  },

  methods: {

    // 点进来重新发请求
    getNewList() {
      // console.log(defaultIndex);
      let subId = this.$route.query.subId
    
      // // 根据我的id找到下标
      let subIndex = (this.cateShopList.categoryL2List || []).findIndex(item => item.id == subId)
      // // this.itemId = item.
      this.defaultIndex = subIndex
      console.log(subIndex)

    },
    toDetail(id){
      this.$router.push({path:'/detail', query: {skuId: id}})
    },


    // 去首页
    toHome() {
      this.$router.push('/home')
    },

    // 去购物车
    toShopCart() {
      this.$router.push('/cart')
    },
    toSearch() {
      this.$router.push('/search')
    },
  },


  computed: {
    ...mapGetters(['cateShopList', 'itemList', 'categoryTitle', 'categoryGroupList', 'categoryL1List']),

  },

}
</script>



<style lang='less' scoped>
.subContainer {
  width: 100%;
  height: 100%;
}

.subContainer .header {
  width: 100%;
  height: 44px;
  background-color: #fff;
  .wb-header {
    height: 50px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    background-color: #fafafa;
    justify-content: space-between;
    .van-icon {
      font-size: 26px;
      color: #333;
    }
    .wb_logo {
      img {
        width: 86px;
        height: 26px;
      }
    }
  }
}
.subContainer .cd-nav {
  position: relative;
  width: 100%;
  background-color: #fff;
  margin-top: -8px;
  ::v-deep .van-tabs__nav--line.van-tabs__nav--complete {
    padding-right: 0.21333rem;
    padding-left: 14px;
    margin-top: 7px;
    width: 100%;
  }
  ::v-deep&::after {
    content: "";
    width: 200px;
    background-color: red;
  }
  ::v-deep .van-tabs__nav--line {
    box-sizing: content-box;
    padding-bottom: 0.4rem;
  }
  ::v-deep .van-tabs__line {
    position: absolute;
    bottom: 22px;
    left: 0;
    z-index: 1;
    width: 65px;
    height: 1px;
    background-color: #ee0a24;
    border-radius: 4px;
  }
  ::v-deep .van-tab--active {
    color: #ee0a24;
    font-weight: 500;
  }
}
.subContainer .bd {
  width: 100%;
  height: 55px;
  margin-top: 50px;
  background-color: #fff;
  ::v-deep .whiteBd {
    width: 100%;
    height: 55px;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    ::v-deep .text {
      font-size: 14px;
      line-height: 30px;
      text-align: center;
      color: #333;
    }
  }
}

.subContainer .shopList {
  width: 100%;
  height: 100%;
}

.subContainer .shopList .two {
  width: 100%;
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  background-color: #fff;
}

.subContainer .shopList .shopItem {
  width: 170px;
  height: 284px;
  padding: 0px 5px 16.5px 10px;
}

.subContainer .shopList .shopItem .itemImg {
  width: 170px;
  height: 170px;
}
.subContainer .shopList .shopItem .itemImg .img {
  width: 170px;
  height: 170px;
}
.subContainer .shopList .shopItem .itemName {
  width: 170px;
  height: 40px;
  font-size: 13px;
  margin-top: 5px;
  line-height: 20px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; /** 多行文本溢出...*/
  overflow: hidden;
}

.subContainer .shopList .shopItem .textPrice {
  display: block;
  font-size: 17px;
  color: red;
  margin-top: 5px;
  word-spacing: 2px;
}

.subContainer .statusBar {
  width: 375px;
  height: 32px;
  padding: 15px 0 0;
  background-color: #ccc;
}
.subContainer .statusBar .text {
  width: 132px;
  height: 18px;
  text-align: center;
  line-height: 18px;
  margin-left: 120px;
  font-size: 13px;
  color: #999;
}
</style>